import request from '@/utils/request'

/**
 * 创建队伍
 * @param {Object} teamData - 队伍数据
 * @returns {Promise} API响应
 */
export const createTeamService = (teamData) => {
  return request({
    url: '/teams/create',
    method: 'POST',
    data: teamData
  })
}

/**
 * 获取队伍详情
 * @param {number} teamId - 队伍ID
 * @returns {Promise} API响应
 */
export const getTeamDetailService = (teamId) => {
  return request({
    url: `/teams/${teamId}`,
    method: 'GET'
  })
}

/**
 * 更新队伍信息
 * @param {number} teamId - 队伍ID
 * @param {Object} teamData - 队伍数据
 * @returns {Promise} API响应
 */
export const updateTeamService = (teamId, teamData) => {
  return request({
    url: `/teams/${teamId}`,
    method: 'PUT',
    data: teamData
  })
}

/**
 * 获取教师队伍列表
 * @param {number} teacherId - 教师ID
 * @returns {Promise} API响应
 */
export const getTeacherTeamsService = (teacherId) => {
  return request({
    url: `/teams/teacher/${teacherId}`,
    method: 'GET'
  })
}

/**
 * 获取队员角色列表
 * @returns {Promise} API响应
 */
export const getMemberRolesService = () => {
  return request({
    url: '/member-roles/list',
    method: 'GET'
  })
}

/**
 * 队员打分
 * @param {Object} scoreData - 打分数据 {teamId, studentId, score}
 * @returns {Promise} API响应
 */
export const scoreMemberService = (scoreData) => {
  return request({
    url: '/teams/score',
    method: 'PUT',
    data: scoreData
  })
}

/**
 * 更新队伍信息
 * @param {Object} updateData - 更新数据 {teamId, teamName, teamIntro, currentCompetition, awardInfo}
 * @returns {Promise} API响应
 */
export const updateTeamInfoService = (updateData) => {
  return request({
    url: '/teams/update',
    method: 'PUT',
    data: updateData
  })
}

/**
 * 获取当前教师的队伍信息（组建的队伍 + 入驻的队伍）
 * @returns {Promise} API响应
 */
export const getMyTeamsService = () => {
  return request({
    url: '/teams/my-teams',
    method: 'GET'
  })
}

/**
 * 获取所有队伍列表
 * @returns {Promise} API响应
 */
export const getAllTeamsService = () => {
  return request({
    url: '/teams/all',
    method: 'GET'
  })
}

/**
 * 入驻队伍（专家入驻）
 * @param {number} teamId - 队伍ID
 * @returns {Promise} API响应
 */
export const joinTeamAsExpertService = (teamId) => {
  return request({
    url: `/teams/${teamId}/join`,
    method: 'POST'
  })
}

export const getTeamEditInfoService = (teamId) => {
  return request({
    url: `/teams/${teamId}/edit`,
    method: 'GET'
  })
}


export const updateTeamMembersService = (teamId, updateData) => {
  return request({
    url: `/teams/${teamId}/members`,
    method: 'PUT',
    data: updateData
  })
}

// 搜索队伍
export const searchTeamsService = (keyword) => {
  return request({
    url: '/teams/search',
    method: 'GET',
    params: { keyword }
  })
} 